<?php
/**
 * Created by PhpStorm.
 * User: 吴盼
 * Date: 2018/4/19
 * Time: 1:05
 */

namespace app\index\controller;
use think\facade\Log;

class WebHooks
{
    public function pull()
    {
        //git webhook 自动部署脚本
        //项目存放物理路径,第一次clone时,必须保证该目录为空
        $savePath = "/data/wwwroot/tp.stlhh.org/";
        $gitPath = "https://gitee.com/cqitclub/itclub_tp5.git";//代码仓库
        $email = "1185100045@qq.com";//用户仓库邮箱
        $name = "panpan_w";//仓库用户名,一般和邮箱一致即可

        // 获取push数据内容的方法
//        $requestBody = file_get_contents("php://input");

        // 只需这一行代码便可拉取
        $a = exec("cd {$savePath} && git pull"); // 目录换成项目的目录
//        $a = exec("cd {$savePath} && ls -a"); // 目录换成项目的目录
//        Log::write($requestBody,'notice');
        Log::write($a,'notice');
        return var_dump($a);

    }


    public function testPull()
    {
        $savePath = "/data/wwwroot/tp.stlhh.org/";
        $a = exec("cd {$savePath} &&sudo git pull");
        return $a;
    }
}
